<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="Maxim Sokhatsky" />
<title>MQTT</title>
<link rel="stylesheet" href="https://n2o.dev/blank.css?x=15" />
<link rel="stylesheet" href="https://n2o.dev/zima.css?x=15" />
<link rel="shortcut icon" type="image/x-icon" href="../img/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="../img/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="../img/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="../img/favicon-16x16.png" />
<link rel="manifest" href="../img/site.webmanifest" />
</head>
<body>
<nav>
  <a href="https://n2o.dev">DEV</a>
  <a href="https://ws.n2o.dev">N2O</a>
  <a href="#" style="background:#ededed;">MQTT</a>
  <div class="dropdown">
    <a onclick="drop()" class="dropbtn">EN</a>
    <div id="dropdown" class="dropdown-content">
      <a href="https://n2o.dev/ua/deps/n2o/man/n2o_mqtt.htm">UA</a>
      <a href="n2o_mqtt.htm">EN</a>
    </div>
  </div>
</nav>
<header>
  <a href="../index.html"><img src="https://openmoji.org/data/color/svg/2B55.svg" /></a>
  <h1>MQTT</h1>
</header>
<main>
<article>
  <section>
    <h3>INTRO</h3>
    <p><b><a href="https://github.com/synrc/n2o/blob/master/src/mqtt/n2o_mqtt.erl">n2o_mqtt</a></b>
      is an instance of <a href="n2o_pi.htm">n2o_pi</a> process. In N2O
      number of such instanses is usually equals to the number of cores.</p>
    <p>There is two styles of embedding N2O: one is to perform N2O protocol loop inside
      connection process (as in cowboy version); second is to spawn ring of n2o_pi
      processes and handle all requests inside these processes (as in MQTT version). n2o_mqtt is
      the protocol of such virtual node processes.</p>
  </section>
  <section>
    <h3>PROTOCOL</h3>
    <p>On <b>init</b> n2o_mqtt makes connection to MQTT server.
      On connection established in <b>#mqttc/2</b> it subscribes to events topic.</p>
    <figure>
      <code>
  events/+/:name/#
      </code>
    </figure>
    <p>After supscription all messages that are being sent to <b>events</b> topic are
      passed as <b>#publish/2</b> where <a href="n2o_proto.htm#info">n2o_proto:info/3</a> protocol loop is
      embedded as handler to that message.</p>
    <figure>
      <code>
  #publish { topic   = [] :: binary(),
             message = [] :: binary()}.

  #mqttc   { client :: pid(),
             status :: connected }.
      </code>
    </figure>
    <p>All the results go to <b>actions</b> topic:</p>
    <figure>
      <code>
  actions/:vsn/:module/:client
      </code>
    </figure>
  </section>
  <section>
    <h3>CONFIG</h3>
    <p>Service workers start MQTT clients with following config:</p>
    <figure>
      <code>
  [{mqtt,[{host, "127.0.0.1"},
          {client_id, Gnerated},
          {clean_sess, false},
          {logger, {console, error}},
          {reconnect, 5}]}].
      </code>
    </figure>
  </section>
  <section>
    <p>This module may refer to:
      <a href="n2o.htm"><b>n2o</b></a>,
      <a href="n2o_pi.htm"><b>n2o_pi</b></a>,
      <a href="n2o_proto.htm"><b>n2o_proto</b></a>.
    </p>
  </section>
</article>
</main>
<footer>2005—2020 © Synrc Research Center</footer>
<script>function drop(){document.getElementById("dropdown").classList.toggle("show");}</script>
</body>
</html>
